import { Injectable, Logger } from '@nestjs/common';
import { Cron, CronExpression } from '@nestjs/schedule';
import { NewsService } from '../news/news.service';
import { WechatService } from '../wechat/wechat.service';
// https://docs.nestjs.com/techniques/task-scheduling#task-scheduling
@Injectable()
export class TasksService {
  private readonly logger = new Logger(TasksService.name);
  constructor(
    private readonly newsService: NewsService,
    private readonly wechatService: WechatService,
  ) {}

  // @Cron(CronExpression.EVERY_10_MINUTES)
  @Cron('0 */5 7-23 * * *')
  async handleCron() {
    this.logger.debug('开始执行定时任务');
    const list = await this.newsService.fetchSituation();
    await this.wechatService.announce(list);
    this.logger.debug('结束执行定时任务');
  }

  // @Interval(10*60*1000)
  // handleInterval() {

  // }

  // @Timeout(20 * 1000)
  // async handleTimeout() {

  // }
}
